﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.ServiceProcess;
using System.Text;
using System.Windows.Forms;

namespace ServiceTest
{
    public partial class Service1 : ServiceBase
    {
        UdpClient udp = new UdpClient(new IPEndPoint(IPAddress.Any, 0));

        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            IPEndPoint ipe = new IPEndPoint(IPAddress.Parse("192.168.1.246"), 5000);
            string sendCmd = "OnStart\r\n";
            byte[] sendByte = Encoding.Default.GetBytes(sendCmd);
            udp.Send(sendByte, sendByte.Length, ipe);

            Form1 fm1 = new Form1();
            fm1.Show();
        }

        protected override void OnStop()
        {
            IPEndPoint ipe = new IPEndPoint(IPAddress.Parse("192.168.1.246"), 5000);
            string sendCmd = "OnStop\r\n";
            byte[] sendByte = Encoding.Default.GetBytes(sendCmd);
            udp.Send(sendByte, sendByte.Length, ipe);

        }
    }
}
